#pragma once
#include<iostream>
using namespace std;

class Date
{
	//全局+友元函数
	friend ostream& operator<<(ostream& out, const Date& d);
	friend istream& operator>>(istream& in, Date& d);

public:
	//构造函数
	Date(int year = 1, int month = 1, int day = 1);

	//取地址运算符重载函数——不写编译器也会自动生成
	Date* operator&()
	{
		cout << "Date* operator&()" << endl;
		return this;
	}

	const Date* operator&() const
	{
		cout << "const Date* operator&() const" << endl;
		return this;
	}

    //const修饰成员函数 this指针权限缩小 普通对象和const对象都能调用
	//需要改变对象成员变量的函数不能用const修饰
	void print() const
	{
		cout << _year << "-" << _month << "-" << _day << endl;
	}

	//拷贝构造函数
	Date(const Date& d)
	{
		_year = d._year;
		_month=d._month;
		_day = d._day;
	}

	bool operator<(const Date& d) const;
	bool operator==(const Date& d) const;
	bool operator<=(const Date& d) const;
	bool operator>=(const Date& d) const;
	bool operator>(const Date& d) const;
	bool operator!=(const Date& d) const;

	int GetMonthday(int year, int month);

	Date& operator+=(int day);
	Date operator+(int day) const;

	Date& operator-=(int day);
	Date operator-(int day) const;

	//前置++  返回++后的对象
	Date& operator++();
	//后置++  返回++前的对象 int是为了用来占位 和++运算符重载函数构成重载 区分前置++和后置++
	Date operator++(int);

	//前置--
	Date& operator--();
	//后置--  
	Date operator--(int);

	int operator-(const Date & d) const;

	//写成成员变量函数 Date默认为第一个参数 即左操作符 使用起来不符合我们的习惯
	//d1<<cout;   d1.opterator(cout);
	void operator<<(ostream& out);

private:
	int _year;
	int _month;
	int _day;
};

ostream& operator<<(ostream& out,const Date& d);
istream& operator>>(istream& in,Date& d);

